{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 248,
   "id": "19e1ae5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "187d095e",
   "metadata": {},
   "source": [
    "Apriori算法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 249,
   "id": "115f856d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造单项集\n",
    "def createC1(dataSet):\n",
    "    C = []\n",
    "    for transaction in dataSet:\n",
    "        for item in transaction:\n",
    "            if [item] not in C:\n",
    "                C.append([item])\n",
    "    C.sort()\n",
    "    return list(map(frozenset,C))\n",
    "\n",
    "\n",
    "#计算Ck的项集在原始记录D中的支持度\n",
    "def scanD(D,Ck,minSupport):\n",
    "    ssCnt = {}\n",
    "    for tid in D:\n",
    "        for can in Ck:\n",
    "            if can.issubset(tid):\n",
    "                ssCnt[can] = ssCnt.get(can,0)+1\n",
    "    numItems = float(len(D))\n",
    "    retList = []\n",
    "    supportData = {}\n",
    "    for key in ssCnt:\n",
    "        support = ssCnt[key]/numItems\n",
    "        if support >= minSupport:\n",
    "            retList.insert(0,key)\n",
    "        supportData[key] = support\n",
    "    return retList,supportData\n",
    "\n",
    "# 生成新的候选项集\n",
    "def aprioriGen(Ck,k):\n",
    "    retList = []\n",
    "    lenCk = len(Ck)\n",
    "    for i in range(lenCk):\n",
    "        for j in range(i+1,lenCk):\n",
    "            L1 = list(Ck[i])[:k-2]\n",
    "            L2 = list(Ck[j])[:k-2]\n",
    "            L1.sort()\n",
    "            L2.sort()\n",
    "            if L1 == L2:\n",
    "                retList.append(Ck[i]|Ck[j])\n",
    "    return retList\n",
    "\n",
    "# 返回所有满足最小支持度的项集\n",
    "def apriori(D,minSupport):\n",
    "    C1=createC1(D)\n",
    "    L1,suppData = scanD(D,C1,minSupport)\n",
    "    L=[L1]\n",
    "    k=2\n",
    "    while (len(L[k-2])>0):\n",
    "        Ck = aprioriGen(L[k-2],k)\n",
    "        Lk,supK=scanD(D,Ck,minSupport)\n",
    "        suppData.update(supK)\n",
    "        L.append(Lk)\n",
    "        k+=1\n",
    "    return L,suppData\n",
    "\n",
    "# 满足最小置信度要求的规则\n",
    "def calcConf(freqSet,H,supportData,brl,minConf=0.7):\n",
    "    prunedH = []\n",
    "    for conseq in H:\n",
    "        conf=supportData[freqSet]/supportData[freqSet-conseq]\n",
    "        if conf >= minConf:\n",
    "            print(freqSet - conseq,'-->',conseq,'conf',conf)\n",
    "            brl.append((freqSet-conseq,conseq,conf))\n",
    "            prunedH.append(conseq)\n",
    "    return prunedH\n",
    "\n",
    "# 对频繁项集中元素超过2的项集进行合并\n",
    "def rulesFormConseq(freqSet,H,suppData,brl,minConf=0.7):\n",
    "    m = len(H[0])\n",
    "    if len(freqSet)>m+1:\n",
    "        Hmp1 = aprioriGen(H,m+1)\n",
    "        Hmp1 = calcConf(freqSet,Hmp1,suppData,brl,minConf)\n",
    "        if len(Hmp1)>1:\n",
    "            rulesFormConseq(freqSet,Hmp1,suppData,brl,minConf)\n",
    "\n",
    "# 根据频繁项集和最小可信度生产规则\n",
    "def generateRules(L,supportData,minConf=0.7):\n",
    "    bigRuleList=[]\n",
    "    for i in range(1,len(L)):\n",
    "        for freqSet in L[i]:\n",
    "            H1 = [frozenset([item]) for item in freqSet]\n",
    "            if i>1:\n",
    "                rulesFormConseq(freqSet,H1,supportData,bigRuleList,minConf)\n",
    "            else:\n",
    "                calcConf(freqSet,H1,supportData,bigRuleList,minConf)\n",
    "    return bigRuleList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7697047e",
   "metadata": {},
   "source": [
    "导入数据文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "id": "c661b1d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cardid</th>\n",
       "      <th>value</th>\n",
       "      <th>pmethod</th>\n",
       "      <th>sex</th>\n",
       "      <th>homeown</th>\n",
       "      <th>income</th>\n",
       "      <th>age</th>\n",
       "      <th>fruitveg</th>\n",
       "      <th>freshmeat</th>\n",
       "      <th>dairy</th>\n",
       "      <th>cannedveg</th>\n",
       "      <th>cannedmeat</th>\n",
       "      <th>frozenmeal</th>\n",
       "      <th>beer</th>\n",
       "      <th>wine</th>\n",
       "      <th>softdrink</th>\n",
       "      <th>fish</th>\n",
       "      <th>confectionery</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>39808</td>\n",
       "      <td>42.7123</td>\n",
       "      <td>CHEQUE</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>27000</td>\n",
       "      <td>46</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>67362</td>\n",
       "      <td>25.3567</td>\n",
       "      <td>CASH</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>30000</td>\n",
       "      <td>28</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10872</td>\n",
       "      <td>20.6176</td>\n",
       "      <td>CASH</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>13200</td>\n",
       "      <td>36</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>26748</td>\n",
       "      <td>23.6883</td>\n",
       "      <td>CARD</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>12200</td>\n",
       "      <td>26</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>91609</td>\n",
       "      <td>18.8133</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>YES</td>\n",
       "      <td>11000</td>\n",
       "      <td>24</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>31384</td>\n",
       "      <td>37.2056</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>27500</td>\n",
       "      <td>27</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>63996</td>\n",
       "      <td>13.7353</td>\n",
       "      <td>CHEQUE</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>22600</td>\n",
       "      <td>23</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>99025</td>\n",
       "      <td>29.0798</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>YES</td>\n",
       "      <td>27400</td>\n",
       "      <td>42</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>95921</td>\n",
       "      <td>34.8576</td>\n",
       "      <td>CASH</td>\n",
       "      <td>F</td>\n",
       "      <td>YES</td>\n",
       "      <td>23300</td>\n",
       "      <td>43</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>99164</td>\n",
       "      <td>30.6965</td>\n",
       "      <td>CASH</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>21600</td>\n",
       "      <td>26</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     cardid    value pmethod sex homeown  income  age fruitveg freshmeat  \\\n",
       "0     39808  42.7123  CHEQUE   M      NO   27000   46        F         T   \n",
       "1     67362  25.3567    CASH   F      NO   30000   28        F         T   \n",
       "2     10872  20.6176    CASH   M      NO   13200   36        F         F   \n",
       "3     26748  23.6883    CARD   F      NO   12200   26        F         F   \n",
       "4     91609  18.8133    CARD   M     YES   11000   24        F         F   \n",
       "..      ...      ...     ...  ..     ...     ...  ...      ...       ...   \n",
       "995   31384  37.2056    CARD   M      NO   27500   27        F         F   \n",
       "996   63996  13.7353  CHEQUE   F      NO   22600   23        F         F   \n",
       "997   99025  29.0798    CARD   M     YES   27400   42        F         T   \n",
       "998   95921  34.8576    CASH   F     YES   23300   43        T         F   \n",
       "999   99164  30.6965    CASH   M      NO   21600   26        F         F   \n",
       "\n",
       "    dairy cannedveg cannedmeat frozenmeal beer wine softdrink fish  \\\n",
       "0       T         F          F          F    F    F         F    F   \n",
       "1       F         F          F          F    F    F         F    F   \n",
       "2       F         T          F          T    T    F         F    T   \n",
       "3       T         F          F          F    F    T         F    F   \n",
       "4       F         F          F          F    F    F         F    F   \n",
       "..    ...       ...        ...        ...  ...  ...       ...  ...   \n",
       "995     F         T          F          F    F    F         F    F   \n",
       "996     F         T          F          F    F    F         F    T   \n",
       "997     F         F          F          F    F    F         F    F   \n",
       "998     F         F          F          F    F    T         F    F   \n",
       "999     T         F          F          F    F    F         T    F   \n",
       "\n",
       "    confectionery  \n",
       "0               T  \n",
       "1               T  \n",
       "2               F  \n",
       "3               F  \n",
       "4               F  \n",
       "..            ...  \n",
       "995             F  \n",
       "996             F  \n",
       "997             F  \n",
       "998             T  \n",
       "999             T  \n",
       "\n",
       "[1000 rows x 18 columns]"
      ]
     },
     "execution_count": 250,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file = pd.read_csv(\"basketdata\")\n",
    "file"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9190ed0",
   "metadata": {},
   "source": [
    "数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "id": "5ea0190e",
   "metadata": {},
   "outputs": [],
   "source": [
    "data  = file.iloc[:,7:]#取出第7列之后的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "id": "3abde4d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将T替换成商品名称，F替换成0\n",
    "for n in data.columns:\n",
    "    data[n] = data[n].replace(\"T\",n)\n",
    "    data[n] = data[n].replace(\"F\",0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "id": "d6700496",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义一个列表存放每一行删除0之后的数据列表\n",
    "data2Dlist = []\n",
    "for i,r in data.iterrows():\n",
    "    list1 = r.tolist()  #将每一行数据转换为列表\n",
    "    while 0 in list1:  #判断列表中是否含有0\n",
    "        list1.remove(0) #删除列表里的0\n",
    "    if list1:  #过滤为空的列表\n",
    "        data2Dlist.append(list1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "id": "57977980",
   "metadata": {},
   "outputs": [],
   "source": [
    "L1,suD2=apriori(data2Dlist,0.15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "id": "425ad49b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[frozenset({'cannedmeat'}),\n",
       "  frozenset({'softdrink'}),\n",
       "  frozenset({'fruitveg'}),\n",
       "  frozenset({'wine'}),\n",
       "  frozenset({'frozenmeal'}),\n",
       "  frozenset({'fish'}),\n",
       "  frozenset({'cannedveg'}),\n",
       "  frozenset({'beer'}),\n",
       "  frozenset({'freshmeat'}),\n",
       "  frozenset({'dairy'}),\n",
       "  frozenset({'confectionery'})],\n",
       " [frozenset({'confectionery', 'wine'}),\n",
       "  frozenset({'fish', 'fruitveg'}),\n",
       "  frozenset({'beer', 'cannedveg'}),\n",
       "  frozenset({'beer', 'frozenmeal'}),\n",
       "  frozenset({'cannedveg', 'frozenmeal'})],\n",
       " [frozenset({'beer', 'cannedveg', 'frozenmeal'})],\n",
       " []]"
      ]
     },
     "execution_count": 256,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "id": "ff91a38f",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{frozenset({'confectionery'}): 0.2936170212765957, frozenset({'dairy'}): 0.18829787234042553, frozenset({'freshmeat'}): 0.1946808510638298, frozenset({'beer'}): 0.31170212765957445, frozenset({'cannedveg'}): 0.3223404255319149, frozenset({'fish'}): 0.31063829787234043, frozenset({'frozenmeal'}): 0.32127659574468087, frozenset({'wine'}): 0.30531914893617024, frozenset({'fruitveg'}): 0.3180851063829787, frozenset({'softdrink'}): 0.19574468085106383, frozenset({'cannedmeat'}): 0.2170212765957447, frozenset({'freshmeat', 'dairy'}): 0.035106382978723406, frozenset({'confectionery', 'freshmeat'}): 0.0574468085106383, frozenset({'confectionery', 'dairy'}): 0.059574468085106386, frozenset({'fish', 'frozenmeal'}): 0.09574468085106383, frozenset({'cannedveg', 'frozenmeal'}): 0.18404255319148935, frozenset({'beer', 'frozenmeal'}): 0.18085106382978725, frozenset({'cannedveg', 'fish'}): 0.09468085106382979, frozenset({'beer', 'fish'}): 0.09042553191489362, frozenset({'cannedveg', 'beer'}): 0.1776595744680851, frozenset({'dairy', 'wine'}): 0.04893617021276596, frozenset({'fish', 'wine'}): 0.08297872340425531, frozenset({'freshmeat', 'wine'}): 0.052127659574468084, frozenset({'freshmeat', 'fish'}): 0.05106382978723404, frozenset({'softdrink', 'fruitveg'}): 0.059574468085106386, frozenset({'frozenmeal', 'fruitveg'}): 0.09148936170212765, frozenset({'fish', 'fruitveg'}): 0.15425531914893617, frozenset({'wine', 'fruitveg'}): 0.08936170212765958, frozenset({'cannedveg', 'fruitveg'}): 0.09148936170212765, frozenset({'freshmeat', 'fruitveg'}): 0.0627659574468085, frozenset({'dairy', 'fruitveg'}): 0.06595744680851064, frozenset({'cannedveg', 'wine'}): 0.10319148936170212, frozenset({'dairy', 'fish'}): 0.059574468085106386, frozenset({'cannedveg', 'freshmeat'}): 0.05851063829787234, frozenset({'cannedveg', 'dairy'}): 0.04680851063829787, frozenset({'cannedmeat', 'frozenmeal'}): 0.0797872340425532, frozenset({'cannedmeat', 'fish'}): 0.06702127659574468, frozenset({'cannedmeat', 'dairy'}): 0.03297872340425532, frozenset({'dairy', 'frozenmeal'}): 0.05425531914893617, frozenset({'softdrink', 'fish'}): 0.05531914893617021, frozenset({'softdrink', 'dairy'}): 0.03723404255319149, frozenset({'softdrink', 'frozenmeal'}): 0.0574468085106383, frozenset({'softdrink', 'beer'}): 0.047872340425531915, frozenset({'confectionery', 'fruitveg'}): 0.08723404255319149, frozenset({'confectionery', 'wine'}): 0.15319148936170213, frozenset({'confectionery', 'fish'}): 0.09148936170212765, frozenset({'confectionery', 'cannedveg'}): 0.07553191489361702, frozenset({'cannedmeat', 'fruitveg'}): 0.06489361702127659, frozenset({'cannedmeat', 'wine'}): 0.0574468085106383, frozenset({'cannedveg', 'cannedmeat'}): 0.07765957446808511, frozenset({'cannedmeat', 'beer'}): 0.06382978723404255, frozenset({'freshmeat', 'cannedmeat'}): 0.043617021276595745, frozenset({'beer', 'fruitveg'}): 0.09468085106382979, frozenset({'frozenmeal', 'wine'}): 0.07553191489361702, frozenset({'beer', 'wine'}): 0.08191489361702127, frozenset({'freshmeat', 'frozenmeal'}): 0.05531914893617021, frozenset({'freshmeat', 'beer'}): 0.05, frozenset({'dairy', 'beer'}): 0.047872340425531915, frozenset({'confectionery', 'beer'}): 0.06808510638297872, frozenset({'softdrink', 'freshmeat'}): 0.04468085106382979, frozenset({'confectionery', 'frozenmeal'}): 0.07021276595744681, frozenset({'softdrink', 'wine'}): 0.06382978723404255, frozenset({'confectionery', 'softdrink'}): 0.05531914893617021, frozenset({'cannedveg', 'softdrink'}): 0.06702127659574468, frozenset({'softdrink', 'cannedmeat'}): 0.04468085106382979, frozenset({'confectionery', 'cannedmeat'}): 0.0574468085106383, frozenset({'frozenmeal', 'cannedveg', 'beer'}): 0.15531914893617021}\n"
     ]
    }
   ],
   "source": [
    "print(suD2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "24a8cd41",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frozenset({'wine'}) --> frozenset({'confectionery'}) conf 0.5017421602787456\n",
      "frozenset({'confectionery'}) --> frozenset({'wine'}) conf 0.5217391304347826\n",
      "frozenset({'beer'}) --> frozenset({'cannedveg'}) conf 0.5699658703071673\n",
      "frozenset({'cannedveg'}) --> frozenset({'beer'}) conf 0.5511551155115512\n",
      "frozenset({'frozenmeal'}) --> frozenset({'beer'}) conf 0.5629139072847682\n",
      "frozenset({'beer'}) --> frozenset({'frozenmeal'}) conf 0.5802047781569967\n",
      "frozenset({'frozenmeal'}) --> frozenset({'cannedveg'}) conf 0.5728476821192052\n",
      "frozenset({'cannedveg'}) --> frozenset({'frozenmeal'}) conf 0.570957095709571\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[(frozenset({'wine'}), frozenset({'confectionery'}), 0.5017421602787456),\n",
       " (frozenset({'confectionery'}), frozenset({'wine'}), 0.5217391304347826),\n",
       " (frozenset({'beer'}), frozenset({'cannedveg'}), 0.5699658703071673),\n",
       " (frozenset({'cannedveg'}), frozenset({'beer'}), 0.5511551155115512),\n",
       " (frozenset({'frozenmeal'}), frozenset({'beer'}), 0.5629139072847682),\n",
       " (frozenset({'beer'}), frozenset({'frozenmeal'}), 0.5802047781569967),\n",
       " (frozenset({'frozenmeal'}), frozenset({'cannedveg'}), 0.5728476821192052),\n",
       " (frozenset({'cannedveg'}), frozenset({'frozenmeal'}), 0.570957095709571)]"
      ]
     },
     "execution_count": 264,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "generateRules(L1,suD2,0.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68dc0220",
   "metadata": {},
   "source": [
    "# 对比不同性别和年龄段顾客的啤酒选择倾向。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "id": "446247ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cardid</th>\n",
       "      <th>value</th>\n",
       "      <th>pmethod</th>\n",
       "      <th>sex</th>\n",
       "      <th>homeown</th>\n",
       "      <th>income</th>\n",
       "      <th>age</th>\n",
       "      <th>fruitveg</th>\n",
       "      <th>freshmeat</th>\n",
       "      <th>dairy</th>\n",
       "      <th>cannedveg</th>\n",
       "      <th>cannedmeat</th>\n",
       "      <th>frozenmeal</th>\n",
       "      <th>beer</th>\n",
       "      <th>wine</th>\n",
       "      <th>softdrink</th>\n",
       "      <th>fish</th>\n",
       "      <th>confectionery</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>39808</td>\n",
       "      <td>42.7123</td>\n",
       "      <td>CHEQUE</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>27000</td>\n",
       "      <td>46</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>67362</td>\n",
       "      <td>25.3567</td>\n",
       "      <td>CASH</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>30000</td>\n",
       "      <td>28</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10872</td>\n",
       "      <td>20.6176</td>\n",
       "      <td>CASH</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>13200</td>\n",
       "      <td>36</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>26748</td>\n",
       "      <td>23.6883</td>\n",
       "      <td>CARD</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>12200</td>\n",
       "      <td>26</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>91609</td>\n",
       "      <td>18.8133</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>YES</td>\n",
       "      <td>11000</td>\n",
       "      <td>24</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>31384</td>\n",
       "      <td>37.2056</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>27500</td>\n",
       "      <td>27</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>63996</td>\n",
       "      <td>13.7353</td>\n",
       "      <td>CHEQUE</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>22600</td>\n",
       "      <td>23</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>99025</td>\n",
       "      <td>29.0798</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>YES</td>\n",
       "      <td>27400</td>\n",
       "      <td>42</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>95921</td>\n",
       "      <td>34.8576</td>\n",
       "      <td>CASH</td>\n",
       "      <td>F</td>\n",
       "      <td>YES</td>\n",
       "      <td>23300</td>\n",
       "      <td>43</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>99164</td>\n",
       "      <td>30.6965</td>\n",
       "      <td>CASH</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>21600</td>\n",
       "      <td>26</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     cardid    value pmethod sex homeown  income  age fruitveg freshmeat  \\\n",
       "0     39808  42.7123  CHEQUE   M      NO   27000   46        F         T   \n",
       "1     67362  25.3567    CASH   F      NO   30000   28        F         T   \n",
       "2     10872  20.6176    CASH   M      NO   13200   36        F         F   \n",
       "3     26748  23.6883    CARD   F      NO   12200   26        F         F   \n",
       "4     91609  18.8133    CARD   M     YES   11000   24        F         F   \n",
       "..      ...      ...     ...  ..     ...     ...  ...      ...       ...   \n",
       "995   31384  37.2056    CARD   M      NO   27500   27        F         F   \n",
       "996   63996  13.7353  CHEQUE   F      NO   22600   23        F         F   \n",
       "997   99025  29.0798    CARD   M     YES   27400   42        F         T   \n",
       "998   95921  34.8576    CASH   F     YES   23300   43        T         F   \n",
       "999   99164  30.6965    CASH   M      NO   21600   26        F         F   \n",
       "\n",
       "    dairy cannedveg cannedmeat frozenmeal beer wine softdrink fish  \\\n",
       "0       T         F          F          F    F    F         F    F   \n",
       "1       F         F          F          F    F    F         F    F   \n",
       "2       F         T          F          T    T    F         F    T   \n",
       "3       T         F          F          F    F    T         F    F   \n",
       "4       F         F          F          F    F    F         F    F   \n",
       "..    ...       ...        ...        ...  ...  ...       ...  ...   \n",
       "995     F         T          F          F    F    F         F    F   \n",
       "996     F         T          F          F    F    F         F    T   \n",
       "997     F         F          F          F    F    F         F    F   \n",
       "998     F         F          F          F    F    T         F    F   \n",
       "999     T         F          F          F    F    F         T    F   \n",
       "\n",
       "    confectionery  \n",
       "0               T  \n",
       "1               T  \n",
       "2               F  \n",
       "3               F  \n",
       "4               F  \n",
       "..            ...  \n",
       "995             F  \n",
       "996             F  \n",
       "997             F  \n",
       "998             T  \n",
       "999             T  \n",
       "\n",
       "[1000 rows x 18 columns]"
      ]
     },
     "execution_count": 267,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 270,
   "id": "eb61d366",
   "metadata": {},
   "outputs": [],
   "source": [
    "file[\"ageg\"] = pd.cut(file[\"age\"],[0,30,50,120],labels=[1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "id": "53c938b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cardid</th>\n",
       "      <th>value</th>\n",
       "      <th>pmethod</th>\n",
       "      <th>sex</th>\n",
       "      <th>homeown</th>\n",
       "      <th>income</th>\n",
       "      <th>age</th>\n",
       "      <th>fruitveg</th>\n",
       "      <th>freshmeat</th>\n",
       "      <th>dairy</th>\n",
       "      <th>cannedveg</th>\n",
       "      <th>cannedmeat</th>\n",
       "      <th>frozenmeal</th>\n",
       "      <th>beer</th>\n",
       "      <th>wine</th>\n",
       "      <th>softdrink</th>\n",
       "      <th>fish</th>\n",
       "      <th>confectionery</th>\n",
       "      <th>ageg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>39808</td>\n",
       "      <td>42.7123</td>\n",
       "      <td>CHEQUE</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>27000</td>\n",
       "      <td>46</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>67362</td>\n",
       "      <td>25.3567</td>\n",
       "      <td>CASH</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>30000</td>\n",
       "      <td>28</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10872</td>\n",
       "      <td>20.6176</td>\n",
       "      <td>CASH</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>13200</td>\n",
       "      <td>36</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>26748</td>\n",
       "      <td>23.6883</td>\n",
       "      <td>CARD</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>12200</td>\n",
       "      <td>26</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>91609</td>\n",
       "      <td>18.8133</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>YES</td>\n",
       "      <td>11000</td>\n",
       "      <td>24</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>31384</td>\n",
       "      <td>37.2056</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>27500</td>\n",
       "      <td>27</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>63996</td>\n",
       "      <td>13.7353</td>\n",
       "      <td>CHEQUE</td>\n",
       "      <td>F</td>\n",
       "      <td>NO</td>\n",
       "      <td>22600</td>\n",
       "      <td>23</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>99025</td>\n",
       "      <td>29.0798</td>\n",
       "      <td>CARD</td>\n",
       "      <td>M</td>\n",
       "      <td>YES</td>\n",
       "      <td>27400</td>\n",
       "      <td>42</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>95921</td>\n",
       "      <td>34.8576</td>\n",
       "      <td>CASH</td>\n",
       "      <td>F</td>\n",
       "      <td>YES</td>\n",
       "      <td>23300</td>\n",
       "      <td>43</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>99164</td>\n",
       "      <td>30.6965</td>\n",
       "      <td>CASH</td>\n",
       "      <td>M</td>\n",
       "      <td>NO</td>\n",
       "      <td>21600</td>\n",
       "      <td>26</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>F</td>\n",
       "      <td>T</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     cardid    value pmethod sex homeown  income  age fruitveg freshmeat  \\\n",
       "0     39808  42.7123  CHEQUE   M      NO   27000   46        F         T   \n",
       "1     67362  25.3567    CASH   F      NO   30000   28        F         T   \n",
       "2     10872  20.6176    CASH   M      NO   13200   36        F         F   \n",
       "3     26748  23.6883    CARD   F      NO   12200   26        F         F   \n",
       "4     91609  18.8133    CARD   M     YES   11000   24        F         F   \n",
       "..      ...      ...     ...  ..     ...     ...  ...      ...       ...   \n",
       "995   31384  37.2056    CARD   M      NO   27500   27        F         F   \n",
       "996   63996  13.7353  CHEQUE   F      NO   22600   23        F         F   \n",
       "997   99025  29.0798    CARD   M     YES   27400   42        F         T   \n",
       "998   95921  34.8576    CASH   F     YES   23300   43        T         F   \n",
       "999   99164  30.6965    CASH   M      NO   21600   26        F         F   \n",
       "\n",
       "    dairy cannedveg cannedmeat frozenmeal beer wine softdrink fish  \\\n",
       "0       T         F          F          F    F    F         F    F   \n",
       "1       F         F          F          F    F    F         F    F   \n",
       "2       F         T          F          T    T    F         F    T   \n",
       "3       T         F          F          F    F    T         F    F   \n",
       "4       F         F          F          F    F    F         F    F   \n",
       "..    ...       ...        ...        ...  ...  ...       ...  ...   \n",
       "995     F         T          F          F    F    F         F    F   \n",
       "996     F         T          F          F    F    F         F    T   \n",
       "997     F         F          F          F    F    F         F    F   \n",
       "998     F         F          F          F    F    T         F    F   \n",
       "999     T         F          F          F    F    F         T    F   \n",
       "\n",
       "    confectionery ageg  \n",
       "0               T    2  \n",
       "1               T    1  \n",
       "2               F    2  \n",
       "3               F    1  \n",
       "4               F    1  \n",
       "..            ...  ...  \n",
       "995             F    1  \n",
       "996             F    1  \n",
       "997             F    2  \n",
       "998             T    2  \n",
       "999             T    1  \n",
       "\n",
       "[1000 rows x 19 columns]"
      ]
     },
     "execution_count": 271,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebcbed07",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
